/**
 * 
 */
package com.net.dao;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.net.domain.ClassHourMapping;
import com.net.domain.ClassHours;
import com.net.domain.ClassInfo;
import com.net.domain.Course;
import com.net.domain.CycleTest;
import com.net.domain.Subject;

/**
 * @author Dinesh
 *
 */
public class MetaUtilDao {
final static Logger log = Logger.getLogger(MetaUtilDao.class);
	
	private SqlMapClient sqlMapClient;
	
	@SuppressWarnings("unchecked")
	public List<ClassInfo> getAllClass () {
		List<ClassInfo> list = null;
		
		try {
			list = (List<ClassInfo>)sqlMapClient.queryForList("getAllClass");
		}
		catch (Exception e) {
			log.error("Error caught while retrieving Class details" + e.getMessage(), e);
		}
		
		return list;		
	}
	@SuppressWarnings("unchecked")
	public List<Course> getAllCourse () {
		List<Course> list = null;
		
		try {
			list = (List<Course>)sqlMapClient.queryForList("getAllCourse");
			log.info("The course count " + list.size());
		}
		catch (Exception e) {
			log.error("Error caught while retrieving Course details" + e.getMessage(), e);
		}
		
		return list;		
	}
	@SuppressWarnings("unchecked")
	public List<Subject> getAllSubject () {
		List<Subject> list = null;
		
		try {
			list = (List<Subject>)sqlMapClient.queryForList("getAllSubject");
		}
		catch (Exception e) {
			log.error("Error caught while retrieving subject details" + e.getMessage(), e);
		}
		
		return list;		
	}
	@SuppressWarnings("unchecked")
	public List<CycleTest> getAllCycleTest () {
		List<CycleTest> list = null;
		
		try {
			list = (List<CycleTest>)sqlMapClient.queryForList("getAllCycleTest");
		}
		catch (Exception e) {
			log.error("Error caught while retrieving test details" + e.getMessage(), e);
		}
		
		return list;		
	}
	@SuppressWarnings("unchecked")
	public List<ClassHours> getAllClassHours () {
		List<ClassHours> list = null;
		
		try {
			list = (List<ClassHours>)sqlMapClient.queryForList("getAllClassHours");
			log.info("The class hours count " + list.size());
		}
		catch (Exception e) {
			log.error("Error caught while retrieving Course details" + e.getMessage(), e);
		}
		
		return list;		
	}
	public ClassInfo getClass(int classId) {
		ClassInfo classinfo = null;
		
		try {
			classinfo = (ClassInfo)sqlMapClient.queryForObject("getClass", classId);
		}
		catch (Exception e) {
			log.error("Error caught while retrieving class details" + e.getMessage(), e);
		}
		
		return classinfo;
	}
	public Course getCourse(int courseId) {
		Course course = null;
		
		try {
			course = (Course)sqlMapClient.queryForObject("getCourse", courseId);
		}
		catch (Exception e) {
			log.error("Error caught while retrieving course details" + e.getMessage(), e);
		}
		
		return course;
	}
	public Subject getSubject(int subjectId) {
		Subject subject = null;
		
		try {
			subject = (Subject)sqlMapClient.queryForObject("getSubject", subjectId);
		}
		catch (Exception e) {
			log.error("Error caught while retrieving subject details" + e.getMessage(), e);
		}
		
		return subject;
	}
	public ClassHours getClassHours(int classHourId) {
		ClassHours classHours = null;
		
		try {
			classHours = (ClassHours)sqlMapClient.queryForObject("getClassHour", classHourId);
		}
		catch (Exception e) {
			log.error("Error caught while retrieving class hour details" + e.getMessage(), e);
		}
		
		return classHours;
	}
	
	@SuppressWarnings("deprecation")
	public int getClassHourMapId(String classHour, Date date,
			int subjectClassGroupId) {
		int classId = 0;
		
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("classHour", classHour);
		map.put("day", String.valueOf(date.getDay()));
		map.put("subjectClassGroupId", String.valueOf(subjectClassGroupId));
		
		try {
			classId = (Integer)sqlMapClient.queryForObject("getClassHourId", map  );
		}
		catch (Exception e) {
			log.error("Error caught while retrieving class hour details" + e.getMessage(), e);
		}
		
		return classId;
	}
	
	@SuppressWarnings("unchecked")
	public List<ClassHourMapping> getClassForStaff(int staffId) {
		
		List<ClassHourMapping> classList = null;		
		
		try {
			classList = (List<ClassHourMapping>)sqlMapClient.queryForList("getStaffCurrentSubjects", staffId );
		}
		catch (Exception e) {
			log.error("Error caught while retrieving class hour details" + e.getMessage(), e);
		}
		
		return classList;
	}
	
	
	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}
	
	@Autowired
	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	
}
